#pragma once
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string>
#include <unistd.h>
#include <cstring>
#include "ditcinit.hpp"
#include "SerResource.hpp"
#include "protocol.hpp"
namespace mytask
{
#define SIZE 1024


    class Task
    {
    public:
        Task(const int& sockfd,SocketInter::SockIn * sk,MyResource::SerResource * sr)
            :_sockfd(sockfd)
            ,_port(sk->GetClientport())
            ,_ip(sk->GetClientip())
            ,_sr(sr)
        {}
        Task()
        {}
        void run()
        {
            
            char buf[SIZE];
            int n = read(_sockfd,buf,sizeof(buf));
            if(n > 0)
            {
                buf[n] = 0;


                //write(_sockfd,str.c_str(),str.size());
            }
            else if(n == 0)
            {
                std::cout << "client quit"<<std::endl;
            }
            else
            {
                std::cout << "server read errno:" << errno << ",strerror"<<strerror(errno)<<std::endl;
            }
            
            close(_sockfd);
        }
        void operator()()
        {
            run();
        }
    private:
        int _sockfd;
        uint16_t _port;
        std::string _ip;
        MyResource::SerResource * _sr;
    };
}
